﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithms
{
    /// <summary>
    /// 数字回文判断
    /// https://leetcode.com/problems/palindrome-number/
    /// </summary>
    public class PalindromeNumber
    {
        public static bool Action1(int x)
        {
            string s = x.ToString();

            int l = s.Length;
            int loop = (s.Length / 2);
            if (l == 0 || loop == 0)
            {
                return true;
            }

            int i = 0;

            for (i = 0; i < loop; i++)
            {
                if (s[i] != s[l - 1 - i])
                {
                    break;
                }
            }

            return i == loop;
        }

        public static bool Action2(int x)
        {
            int o = x;
            if (x < 0)
            {
                return false;
            }

            long r = 0;

            while (x>0)
            {
                int d=x % 10;
                r = r * 10 + d;
                x = x / 10;
            }
            return r == o;
        }

        public static bool Action3(int x)
        {
            if (x < 0||(x%10==0&&x!=0))
            {
                return false;

            }
            if (x < 10)
            {
                return true;

            }
            int r = 0;

            while (x > 0&&x>r)
            {
                int d = x % 10;
                r = r * 10 + d;
                x = x / 10;
            }
            return (x==r||x==r/10); 
        }
    }
}
